home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / 251_01.zip / PULLDOWN.C < prev    next >
Text File  |  1993-04-01  |  21KB  |  820 lines

  1. /*   COPYRIGHT (C) 1986 */
  2. /*   BY JAMES L PINSON  */
  3. /*  ALL RIGHTS RESERVED */
  4.  
  5.  
  6. /* Compiled with Lattice C V2.14 */
  7. /* Computer: IBM PC JR           */
  8. /* Text editor: Sidekick         */
  9. /* Last revision 3/16/1987       */
  10.  
  11.  
  12.  
  13. #include  "stdio.h"
  14. #include  "ctype.h"
  15.  
  16. #define void int
  17.  
  18.  
  19. #define BLACK   0        /*  THESE ARE FOR COLOR CARDS */
  20. #define BLUE    1
  21. #define GREEN   2
  22. #define CYAN    3
  23. #define RED     4
  24. #define MAGENTA 5
  25. #define BROWN   6
  26. #define WHITE   7
  27. #define L_BLUE  9     /* LIGHT-BLUE FOREGROUND ONLY */
  28. #define L_GREEN 10    /* LIGHT-GREEN FOREGROUND ONLY */
  29. #define YELLOW  14
  30. #define IWHITE  15    /* INTENSE-WHITE FOREGROUND ONLY*/
  31.  
  32.  
  33.  
  34. #define UNDERLINE 1     /* THESE ARE FOR MONOCHROME CARDS */
  35. #define NORMAL    7
  36. #define HI_INTEN  15
  37. #define REVERSE   112
  38.  
  39. #define TRUE  1
  40. #define FALSE 0
  41.  
  42. unsigned int page;          /* extern decl. for functions*/
  43. unsigned int attribute;
  44. unsigned int mon_type;
  45. char wrt_meth= 'f';
  46.  
  47.  
  48.  
  49. #define  NU_MAIN 5        /* number of main menu options */
  50. #define  NU_SUB  5        /* number of sub menu options  */
  51.  
  52.  struct menu_str{        /* change this if you need more options */
  53.     char *head;
  54.     char *body[NU_SUB];
  55.     void (*fun1)();
  56.     void (*fun2)();
  57.     void (*fun3)();
  58.     void (*fun4)();
  59.     void (*fun5)();
  60.   } ;
  61.  
  62.  
  63. main(argc,argv)
  64.      int argc;
  65.      char **argv;
  66. {
  67. extern unsigned int page;
  68. extern unsigned int attribute;
  69. extern unsigned int mon_type;
  70.  
  71. char ch,ext;
  72.  
  73. int i,hi_attr,nor_attr;
  74.  
  75. int demo();
  76. int help();
  77.  
  78.  static  struct menu_str m_menu [NU_MAIN]={
  79.  
  80.      "   File   ",   /*  The first menu option       */
  81.        "   Dir      ",   /*  Menu sub options */
  82.        "   Load     ",
  83.        "   Save     ",
  84.        "   dElete   ",
  85.        "   Path     ",
  86.                 demo,   /* The functions each sub-option call */
  87.                 demo,
  88.                 demo,    /* these all call the same fake function */
  89.                 demo,
  90.                 demo,
  91.  
  92.        "   fiNd   ",           /* The second menu option */
  93.          " All-words  ",
  94.          " First-word ",
  95.          "\0",
  96.          "\0",           /* space filler for unused option names */
  97.          "\0",
  98.                 demo,
  99.                 demo,
  100.                 0,       /* unused function pointer */
  101.                 0,
  102.                 0,
  103.  
  104.        "   Configure   ",    /* The third option */
  105.          " Modem ",
  106.          " Screen ",
  107.          " Printer ",
  108.          "\0",
  109.          "\0",
  110.                 demo,
  111.                 demo,
  112.                 demo,
  113.                 0,
  114.                 0,
  115.  
  116.        "        Output       ",           /* The fourth menu option */
  117.          "  Screen  ",
  118.          "  Printer ",
  119.          "  Disk    ",
  120.          "  Modem   ",
  121.          "\0",
  122.                 demo,
  123.                 demo,
  124.                 demo,
  125.                 demo,
  126.                 0,
  127.  
  128.  
  129.            " Help ",                       /* The fifth option */
  130.            " Instant help (really works) ",
  131.            "\0",
  132.            "\0",
  133.            "\0",
  134.            "\0",
  135.                 help,
  136.                 0,
  137.                 0,
  138.                 0,
  139.                 0,
  140. };
  141.  
  142.  
  143. /* was a slow write requested? */
  144. if (tolower (*argv[1])== 's') wrt_meth = 's';
  145.  
  146. page=0;
  147.  
  148.  
  149.  mon_type =(what_mon());
  150.  
  151.   if (mon_type==1){                     /* FIND OUT IF YOU HAVE A COLOR CARD */
  152.     hi_attr=  set_color(BLACK,CYAN);    /* AND SET ATTRIBUTES ACCORDINGLY */
  153.     nor_attr= set_color(WHITE,BLACK);
  154.   }
  155.     else{
  156.      hi_attr = REVERSE;
  157.      nor_attr = NORMAL;
  158.     }
  159.  
  160.  attribute = nor_attr;
  161.  cursor(0);               /* hide cursor */
  162.  win_save('s');
  163.  cls();
  164.  
  165.  if (mon_type==1) make_help();
  166.  
  167.  make_inst();          /* SHOW INSTRUCTIONS */
  168.  
  169.  menu(m_menu,NU_MAIN,NU_SUB,hi_attr,nor_attr);
  170.  
  171.  win_save('r');        /* restore text display*/
  172.  cursor(1);            /* restore cursor      */
  173. }
  174.  
  175.  
  176. int menu (m_menu,nu_main,nu_sub,hi_attr,nor_attr)
  177. struct menu_str m_menu[];
  178. int nu_main,nu_sub,hi_attr, nor_attr;
  179.  
  180. {
  181. extern unsigned int page;
  182. extern unsigned int attribute;
  183. extern unsigned int mon_type;
  184.  
  185. int i,j,k,cur_x,cur_y,cur_opt,found,expert=1;
  186. char ch, ext, ltr;
  187.  
  188.    ch= ' ';ext=' '; cur_opt=0; found =0;
  189.  
  190. if (mon_type==1) attribute = set_color(YELLOW,BLACK);
  191. else attribute = nor_attr;
  192.  
  193. make_window(1,1,78,1,1);
  194.  
  195.  
  196.   for(;;){               /* endless loop */
  197.  
  198.         for(i=0;i<nu_main;i++){
  199.           j=0;
  200.           while(ltr = m_menu[i].head[j++]){
  201.             if ( ch==ltr && ch != ' '){
  202.              found= TRUE;
  203.              cur_opt = i;
  204.             }
  205.           }
  206.         }
  207.           if (ch==13){
  208.            found = TRUE;
  209.            expert = FALSE;
  210.           }
  211.  
  212.                    ch=' ';
  213.                    cur_x=2;cur_y=2;
  214.  
  215.  
  216.                for(i=0;i< nu_main;i++){
  217.                    if(i == cur_opt) attribute= hi_attr;
  218.                     else attribute= nor_attr;
  219.                      print(cur_x,cur_y,m_menu[i].head);
  220.  
  221.                  cur_x= cur_x+strlen(m_menu[i].head)+3;
  222.                 }
  223.  
  224.            if (!expert) found = TRUE;
  225.  
  226.            if (found){
  227.  
  228.              ext =(pull_down(m_menu,nu_sub,cur_opt)); /* pull-down options */
  229.              if (ext == 27) expert = TRUE;
  230.              if (ext == 'r' || ext == 'l') expert = FALSE;
  231.              if (ext=='r') cur_opt = cur_opt+1;
  232.              if (ext =='l') cur_opt = cur_opt -1;
  233.              ch= ' ';
  234.              ext= ' ';
  235.  
  236.             }
  237.  
  238.            if(!found){
  239.             ch=' ';
  240.             get_key(&ch,&ext);
  241.  
  242.             ch=toupper(ch);
  243.  
  244.           }
  245.  
  246.            if (ch==27) return;
  247.  
  248.            if (ext =='r' || ext == 'l') expert = 0;
  249.            if (ext == 'r')  cur_opt = cur_opt +1;
  250.            if (ext == 'l')  cur_opt = cur_opt -1;
  251.            if (cur_opt >= nu_main) cur_opt =0;
  252.            if (cur_opt < 0) cur_opt = nu_main-1;
  253.            ext=' ';
  254.            found=0;
  255.  
  256.   } /* end for(;;) */
  257.  
  258. }   /* end function */
  259.  
  260.  
  261.  
  262. int pull_down(m_menu,nu_sub,position)
  263. struct menu_str m_menu[];
  264. int position;
  265.  
  266. {
  267. extern unsigned int page;
  268. extern unsigned int attribute;
  269. char ch=' ',ltr;
  270. int ext=' ',hi_attr,nor_attr;
  271. int i,j,tx,ty,start,width,nu_opt,cur_opt=0, found= FALSE;
  272.  
  273. nu_opt = nu_sub;
  274.  
  275. /* nu_sub = number of possible pull-down options */
  276. /* find out how many are in use */
  277.  
  278. for(i=0;i<nu_opt;i++){
  279.   if (m_menu[position].body[i][0] == '\0'){
  280.    nu_opt = i;
  281.    break;
  282.   }
  283.  
  284. }
  285.  
  286.  
  287.   if (mon_type==1){
  288.     hi_attr=  set_color(BLACK,CYAN);
  289.     nor_attr= set_color(WHITE,BLACK);
  290.   }
  291.     else{
  292.      hi_attr = REVERSE;
  293.      nor_attr = NORMAL;
  294.     }
  295.  
  296.  attribute = nor_attr;
  297.  
  298. start=2;       /* figure where to draw pull-down box */
  299.               /* 2 is column to start 1st box */
  300.               /* add up length of menu heads */
  301.  
  302.   for(i=0; i< position; i++)  start= start+strlen(m_menu[i].head)+3;
  303.  
  304.  
  305.   width=0;      /* figure max length of window */
  306.  
  307.   for (i=0;i< nu_opt;i++){
  308.    if (strlen(m_menu[position].body[i]) > width){
  309.     width= strlen(m_menu[position].body[i]);
  310.    }
  311.   }
  312.  
  313.                          /* move box to left if          */
  314.                          /* it will spill off right side */
  315.  
  316.  if(start+width+1>80) start = 80-width-2;
  317.  
  318.  
  319.   win_save ('s');
  320.  
  321.  if (mon_type ==1) attribute = set_color (YELLOW,BLACK);
  322.  
  323.  make_window(start++,3,width,nu_opt,0); /*make a window */
  324.  attribute = nor_attr;
  325.  
  326. tx=start;ty=4;                       /* reposition for writing */
  327.  
  328.   for(;;){
  329.          for(i=0;i< nu_opt;i++){
  330.            if(i == cur_opt) attribute= hi_attr;
  331.             else attribute= nor_attr;
  332.             print(tx,ty++,m_menu[position].body[i]);
  333.          };
  334.  
  335.          attribute = nor_attr;
  336.  
  337.           if(found ) {
  338.              win_save('r');     /* remove box */
  339.  
  340.                 /* if you want more than 5 menu options */
  341.                 /* change this next switch statement    */
  342.  
  343.              switch (cur_opt){       /* call function */
  344.               case 0: (*m_menu[position].fun1)() ;break;
  345.               case 1: (*m_menu[position].fun2)() ;break;
  346.               case 2: (*m_menu[position].fun3)() ;break;
  347.               case 3: (*m_menu[position].fun4)() ;break;
  348.               case 4: (*m_menu[position].fun5)() ;break;
  349.  
  350.              }
  351.  
  352.           /* found = FALSE; */
  353.           if (kbhit()) getch();  /* make sure keyboard buffer is clear */
  354.            return(' ');
  355.           }
  356.  
  357.         tx=start;ty=4;
  358.        get_key(&ch,&ext); ch=toupper(ch);  /* get a character */
  359.            if (ext == 'd')  cur_opt = cur_opt +1;
  360.            if (ext == 'u')  cur_opt = cur_opt -1;
  361.            if (cur_opt >= nu_opt) cur_opt =0;
  362.            if (cur_opt < 0) cur_opt = nu_opt-1;
  363.  
  364.           if (ch== 13) found = TRUE;
  365.  
  366.         for(i=0;i<nu_opt;i++){   /* does it match an option? */
  367.          j=0;
  368.          while(ltr = m_menu[position].body[i][j++]){
  369.             if ( ch==ltr){
  370.              cur_opt = i;
  371.              found = TRUE;
  372.             }
  373.          }
  374.         }
  375.  
  376.            if (ext=='l'|| ext=='r') break;
  377.            if (ch==27){          /* EXIT IF ESCAPE KEY */
  378.             ext = ch;
  379.             break;
  380.            }
  381.            ext=' ';ch=' ';
  382.   } /* end for(;;)*/
  383.   win_save('r');
  384.   return (ext);
  385. }
  386.  
  387.  
  388.  
  389. void make_help()
  390. {
  391.  
  392. extern unsigned int page,attribute;
  393.  
  394.  page=1;
  395.  
  396.  
  397.   print(1,1,"HELLO - THIS IS A SAMPLE OF AN INSTANT HELP SCREEN.");
  398.   print(10,5,"THIS SCREEN WAS PRINTED TO THE SECOND PAGE OF GRAPHICS");
  399.   print(10,7,"WHILE YOU WERE LOOKING AT THE MAIN MENU.");
  400.   print(10,9,"THIS HELP SCREEN CAN BE LEFT UNDISTURBED");
  401.   print(10,11,"AND REDISPLAYED AT ANY TIME.");
  402.   print (1,20,"PLEASE TOUCH ANY KEY TO RETURN TO THE MAIN MENU.");
  403.  
  404.  
  405.  page=0;
  406.  
  407. }
  408.  
  409.  
  410. void make_inst()
  411. {
  412.  extern unsigned int attribute;
  413.  
  414.   if (mon_type==1)
  415.    attribute=  set_color(GREEN,BLACK);
  416.     else
  417.      attribute = NORMAL;
  418.  
  419.  print (1,4,"INSTRUCTIONS:");
  420.  print (1,6,"EXPERT MODE: Select by touching the key which represents each option.");
  421.  print (15,7,"(the capital letter)");
  422.  
  423.  print (1,10, "ASSIST MODE: Pull-down menu by touching 'enter' or a cursor key.");
  424.  print (14,11,"Select by highlighting with cursor keys- then touch return");
  425.  print (14,13,"Return to Expert mode by touching 'escape'");
  426.  
  427.  print (1,15,"EXIT:        Touch 'Escape' while in expert mode.");
  428. }
  429.  
  430.  
  431. void mono_help()
  432. {
  433.  
  434.   attribute=NORMAL;
  435.   win_save('s');
  436.  
  437.   clear_window(1,4,80,21);
  438.   print(1,7,"THIS IS A DEMONSTRATION OF A HELP SCREEN");
  439.   print(1,9,"THIS TEXT WAS WRITTEN BY MEANS OF DIRECT MEMORY ADDRESS");
  440.   print(1,10,"THE ORIGINAL SCREEN HAS BEEN SAVED AND WILL BE RESTORED ");
  441.   print(1,11,"WHEN YOU EXIT THIS 'HELP' SCREEN");
  442.   print(1,14,"PLEASE TOUCH ANY KEY TO CONTINUE");
  443.  
  444.    getch();
  445.   win_save('r');
  446. }
  447.  
  448.  
  449.  
  450. int demo()
  451. {
  452. int hit;
  453. win_save('s');
  454. make_window(20,10,40,5,1);
  455.  
  456. print(21,11,"Put your favorite routine here ");
  457. print (21,14,"touch any key to return to menu");
  458. getch(hit);
  459.  
  460. win_save('r');
  461. }
  462.  
  463.  
  464. int help()
  465. {
  466.  if (mon_type==1){     /*IF COLOR CARD FLIP PAGE TO */
  467.     page=1;            /*SHOW TEXT ELSE WRITE TO CURRENT*/
  468.     d_page();getch();  /* SCREEN*/
  469.     page=0;d_page();
  470.  
  471.  } else mono_help();
  472.  
  473. }
  474.  
  475.  
  476.  
  477.                     /* SCREEN-FUNCTION LIBRAY */
  478.  
  479.  
  480.  
  481. /* DECLARE THE EXTERN VARIABLES        */
  482. /* PAGE,ATTRIBUTE AND MON_TYPE         */
  483. /* (MONITOR TYPE)                      */
  484. /* IN YOUR MAIN PROGRAM                */
  485.  
  486.  
  487.  
  488.  
  489.  
  490. /*** GOTOXY ***/                        /* PUTS CURSOR AT X,Y POSITION */
  491. void gotoxy(x,y)                        /* ON SELECTED PAGE            */
  492. unsigned int x,y;                       /* 1,1 IS UPPER LEFT CORNER    */
  493.  
  494. {
  495.    extern unsigned int page;
  496.  
  497.    struct { unsigned int ax,bx,cx,dx,si,di,ds,es; } regist;
  498.  
  499.    if (x<1 || x>80) return;
  500.    if (y<1 || y>25) return;
  501.    x--;y--;                  /* DOS starts co-ordinates at 0,0 */
  502.  
  503.    regist.ax = 0x0200;
  504.    regist.dx = (y<<8) | x ;
  505.    regist.bx = page<<8;  /*page number*/
  506.  
  507.    int86(0x10, ®ist,®ist);
  508. }
  509.  
  510. /*** WHEREXY ***/        /* RETURNS THE X,Y POSITION OF CURSOR */
  511. int wherexy(x,y)
  512. int *x,*y;
  513.  
  514.  
  515. {
  516.    extern unsigned int page;
  517.  
  518.    struct { unsigned int ax,bx,cx,dx,si,di,ds,es; } regist;
  519.  
  520.  
  521.    regist.ax = 0x0300;
  522.  
  523.    regist.bx = page<<8;  /*page number*/
  524.  
  525.    int86(0x10, ®ist,®ist);
  526.    *x=( (regist.dx & 0x00ff)+1);
  527.    *y= ( ( (regist.dx & 0xff00)>>8)+1);
  528.  
  529. }
  530.  
  531. /*** d_page ***/                 /* DISPLAYS THE PAGE INDICATED  */
  532. void d_page()                    /* BY EXTER VAR PAGE            */
  533.                                  /* USE ONLY WITH COLOR CARD     */
  534.  
  535. {
  536.    extern unsigned int page;
  537.    struct { unsigned int ax,bx,cx,dx,si,di,ds,es; } regist;
  538.    regist.ax = (0x0500|page);
  539.    int86(0x10, ®ist,®ist);
  540. }
  541.  
  542.  
  543.  
  544.  
  545. /*** WIN_SAVE ***/                  /* SAVES OR RESTORES PRIMARY  */
  546. void win_save(action)               /* DISPLAY SCREEN.            */
  547. int action;                         /* (PAGE 0 FOR COLOR DISPLAY) */
  548.                                     /* 's' = SAVE                 */
  549. {                                   /* 'r' = RESTORE              */
  550.  extern unsigned int page;          /*  SAVES CURSOR POSITION TOO */
  551.  extern unsigned int mon_type;      /*  MAY MAKE SNOW ON CGA      */
  552.  int position;
  553.  static int ptr;
  554.  
  555. static struct {
  556.          int x;
  557.          int y;
  558.          unsigned int buffer [4000];
  559.        } window[2];
  560.  
  561.  
  562.    if (mon_type==1) position=0xb800;  /* COLOR CARD */
  563.     else position=0xb000;             /* MONOCHROME */
  564.  
  565.    if (action=='s') {                 /* SAVE */
  566.     if (ptr>1){
  567.      ptr=2;
  568.      return(0);
  569.     }
  570.                           /* peek is a lattice function */
  571.                           /* could use pointer in larger */
  572.                           /* memory model                */
  573.     peek(position,0x00,&window[ptr].buffer,4000);  /* SAVE SCREEN     */
  574.     wherexy(&window[ptr].x,&window[ptr].y);        /* SAVE CURSOR LOC */
  575.     ptr++;
  576.  
  577.    }
  578.  
  579.    if (action=='r') {                 /* RESTORE */
  580.     if(ptr <1){
  581.       ptr = 0;
  582.       return(0);
  583.     }
  584.     ptr-- ;
  585.  
  586.     poke(position,0x00,&window[ptr].buffer,4000); /* RESTORE SCREEN */
  587.     gotoxy(window[ptr].x, window[ptr].y);         /* RESTORE CURSOR */
  588.  
  589.  
  590.  
  591.    }
  592.  
  593. }
  594.  
  595.  
  596.  
  597. /*** SET_COLOR ***/                     /* CALL WITH FORGROUND  */
  598.                                         /* AND BACKGROUND COLOR.*/
  599. int set_color(foreground, background,)  /* RETURNS ATTRIBUTE.   */
  600.   int foreground,background;
  601. {
  602.   return(background<<4|foreground);
  603.  
  604. }
  605.  
  606.  
  607.  
  608. /*** CLEAR_WINDOW ***/                  /* CALL WITH X,Y OF UPPER LEFT   */
  609. void clear_window(x,y,width,height )    /* CORNER OF WINDOW AREA.        */
  610. unsigned int x,y,width,height;          /* CLEARS DOWN AND TO RIGHT      */
  611.                                         /* FOR WIDTH AND HEIGHT.         */
  612. {                                       /* CLEARED WITH ACTIVE ATTRIBUTE */
  613.    extern unsigned int page;            /* USE ON DISPLAYED PAGE ONLY!   */
  614.    extern unsigned int attribute;
  615.    struct { unsigned int ax,bx,cx,dx,si,di,ds,es; } regist;
  616.    x--;y--;
  617.    regist.ax = 0x0600;
  618.    regist.cx = (y<<8) | x ;
  619.    regist.dx =(y+height-1) <<8 |x + width-1 ;
  620.    regist.bx =(attribute<<8);
  621.    int86(0x10, ®ist,®ist);
  622. }
  623.  
  624.  
  625.  
  626. /*** box ***/
  627.  
  628. void box (x,y,width,height,type)    /* type 0 = pull-down box */
  629. int x,y,width,height,type;          /* type 1 = regular box   */
  630.  
  631. {
  632.   int i,j,ctr,u_right,u_left;
  633.   char string[82];
  634.  
  635.   if(type==0){                  /* following sets corners */
  636.    u_left  =   '\xc2';
  637.    u_right =  '\xc2';
  638.   }
  639.  
  640.   if (type == 1){
  641.    u_left = '\xda';
  642.    u_right = '\xbf';
  643.   }
  644.  
  645.      string[0]= u_left;
  646.      for(i=1;i<=width;i++) string[i]='\xc4';
  647.      string[i++]=u_right; string[i]='\0';
  648.      print(x,y++,&string[0]);
  649.  
  650.        for (i=0; i<height;i++){
  651.         print(x,y,"\xb3");
  652.         print(x+width+1,y++,"\xb3");
  653.       }
  654.  
  655.           string[0]='\xc0';
  656.           for(i=1;i<=width;i++) string[i]='\xc4';
  657.           string[i++]='\xd9';string[i]='\0';
  658.           print(x,y++,&string[0]);
  659. }
  660.  
  661.  
  662. int what_mon()          /* RETURNS A 1 IF COLOR CARD PRESENT */
  663. {                       /* RETURNS A 0 IF MONOCHROME CARD    */
  664.  
  665. char mode;        /* CHAR DEFINES AN 8 BIT INTEGER */
  666.  
  667.     peek(0x0040,0x0049,&mode,1);
  668.  
  669.     if (mode==7) return(0);
  670.     else return(1);
  671. }
  672.  
  673.  
  674. void cls()           /* SAME AS DOS CLS */
  675. {
  676. clear_window(1,1,80,25);
  677. gotoxy(1,1);
  678. }
  679.  
  680.  
  681. void make_window(x,y,width,height,type)  /* DRAWS AND CLEARS A BOX */
  682. unsigned int x,y,width,height,type;
  683.  
  684. {
  685.   box(x++,y++,width,height,type);       /* DRAW BOX       */
  686.   clear_window(x,y,width,height);       /* CLEAR INTERIOR */
  687. }
  688.  
  689.  
  690.  
  691. int cursor(size)    /* SETS CURSOR SIZE */
  692. int size;           /* 0= no cursor, 1 = normal, 2= big cursor */
  693. {
  694.  
  695.  struct { int ax,bx,cx,dx,si,di,ds,es; } regist;
  696.  
  697.  regist.ax= 0x0100;
  698.  
  699.     if (mon_type == 1 ){                /* COLOR */
  700.      if (size == 0) regist.cx = 0x0f0f;
  701.      if (size == 1) regist.cx = 0x0607;
  702.      if (size == 2) regist.cx = 0x0107;
  703.     }
  704.  
  705.     if (mon_type == 0 ){                /* MONOCHROME */
  706.      if (size == 0) regist.cx= 0x0f0f;
  707.      if (size == 1) regist.cx = 0x0c0d;
  708.      if (size == 2) regist.cx = 0x010d;
  709.     }
  710.  
  711.    int86(0x10,®ist,®ist);
  712.  
  713. }
  714.  
  715.  
  716.  
  717. /*** PRINT ***/
  718.  
  719. void print(x,y,str)          /* A SWITCHER- ROUTES TO FAST_WRITE */
  720.  unsigned int x,y;           /* OR TO DOS_PRT DEPENDING ON ARGV  */
  721.  char *str;                  /* PASSED TO PROGRAM AND SORED IN   */
  722. {                            /* EXTERN CHAR WR_METH              */
  723.  extern char wrt_meth;
  724.  
  725. if (wrt_meth == 'f')                       /* FAST (DIRECT POKING) */
  726.   if (wrt_meth == 'f') fast_write(x,y,str);
  727.  
  728.   if (wrt_meth == 's') {     /* SLOW (DOS METHOD) */
  729.    gotoxy(x,y);
  730.    dos_prt(str);
  731.   }
  732. }
  733.  
  734. /*** DOS_PRT ***/           /*  ASKS DOS TO WRITE A STRING WITH ATTRIBUTE   */
  735.                             /*  DEFINED. AN ALTERNATIVE TO FAST WRITE IN    */
  736. void dos_prt(str)           /*  THAT IT IS "WELL BEHAVED"(GOES THROUGH DOS) */
  737.                             /*  SPECIFY PAGE AND SET CURSOR POSITION BEFORE */
  738. char *str;                  /*  CALLING   */
  739. {
  740.    extern unsigned int page,attribute;
  741.    unsigned int x,y;
  742.    int c;
  743.  
  744.    struct { unsigned int ax,bx,cx,dx,si,di,ds,es; } regist;
  745.    wherexy(&x,&y);
  746.  
  747.    while (*str) {                      /* WHILE NOT EOF LET DOS WRITE CHAR */
  748.       if (x>80){
  749.          x=1;
  750.          y=y+1;
  751.        }
  752.       if (y>25) break;
  753.       gotoxy(x++,y);
  754.       regist.bx = (page<<8|attribute);
  755.  
  756.       regist.cx = 1;
  757.       regist.ax = 0x0900| *str++;
  758.       int86(0x10, ®ist, ®ist);
  759.  
  760.   }
  761.   gotoxy(x,y);             /* put cursor at end of string */
  762. }
  763.  
  764. /***FAST_WRITE***/               /* DIRECTLY POKES STRING AT X,Y POSITION */
  765. void fast_write(x,y,string)      /* USES ATTRIBUTE AND PAGE.              */
  766. int x,y;                         /* MAY CAUSE SNOW ON SOME GRAPHIC CARDS  */
  767. char *string;
  768.  
  769. {
  770.  extern unsigned int page;
  771.  extern unsigned int attribute;
  772.  extern unsigned int mon_type;   /* MONITOR TYPE */
  773.  
  774.  int position,offset,orig;
  775.  
  776.     if (page <=3 && page >=0) offset = 4000*page+96*page;
  777.       orig = offset;
  778.       offset=offset+((y-1)*160)+(2*(x-1));
  779.       position =0xb800;
  780.  
  781.     if (mon_type ==0) position=0xb000;
  782.  
  783.    while(*string){
  784.         poke(position,offset,string++,1);        /* POKE CHARACTER */
  785.         poke(position,offset+1,&attribute,1);    /* POKE ATTRIBUTE */
  786.         offset=offset+2;
  787.  
  788.    }
  789.          offset = offset- orig;                    /* FIGURE WHERE I AM */
  790.          x= ((offset% 160)/2)+1 ;y= offset/160+1 ; /* AND MOVE CURSOR   */
  791.          gotoxy (x,y);
  792.  
  793. }
  794.  
  795. /*** get_key ***/             /* READ A CHAR             */
  796.                               /* RETURN CHARACTER IN CH  */
  797. int get_key(ch,ext)           /* IF IT IS A FUNCTION KEY */
  798. char *ch;                     /* RETURN FOLLOWING IN EXT */
  799. int  *ext;                    /* UP-ARROW    = 'U'       */
  800.                               /* DOWN-ARROW  = 'D'       */
  801. {                             /* RIGHT-ARROW = 'R'       */
  802.   *ch=getch();                /* LEFT-ARROW  = 'L'       */
  803.  
  804.     if(!*ch){
  805.       *ext=getch();
  806.  
  807.        switch (*ext){
  808.          case 'H' :*ext ='u';break; /*  up    */
  809.          case 'P' :*ext ='d';break; /*  down    */
  810.          case 'M' :*ext ='r';break; /*  right   */
  811.          case 'K' :*ext ='l';break; /*  left    */
  812.          case 'G' :*ext ='h';break; /*  home    */
  813.          case 'O' :*ext ='e';break; /*  end     */
  814.          case 'R' :*ext ='I';break; /*  insert  */
  815.          case 'S' :*ext ='D';break; /*  delete  */
  816.        }
  817.     }
  818. }
  819.  
  820.